A short description of the post.
For Shiny Apps, the code looks foreign and a bit are you serious after all this time I spent learning R coding
Once you get the basic structure, you can easily get started and then it is “Trial and Error”
Understand the core structure of Shiny apps: UI, Server, Reactivity
Learn how to create and run an App locally
Learn how to deploy your App on ARI’s shiny account
Ibis Tracker - Nev masterpiece
https://arisci.shinyapps.io/ibisTracker/
LISTS
#install.packages("shiny")
You can find a variety of cheatsheets at https://posit.co/resources/cheatsheets/
knitr::include_graphics("shiny.pdf")
s
# library(shiny)
# ui <- fluidPage( "Hello, world!" )
# server <- function(input, output, session) { }
# shinyApp(ui, server)
you put R code in renderFunction
extras at < https://github.com/nanxstats/awesome-shiny-extensions>
Let’s create replicate Examples https://shiny.posit.co/r/gallery/
This will become pretty useful for collaborations and your own self-learning. Also, we now have a ARI shiny account and consistency allows for increased sharing and understanding.
can check https://r-graph-gallery.com/interactive-charts.html
library(ggplot2)
library(plotly)
f <- ggplot( cars, aes(speed, dist) ) + geom_point() + geom_smooth()
plotly::ggplotly(f)
I like this one for linking up plots…below, put your cursor over a dot on the left or a bar on the right
If you know CSS, can be pretty powerful…
library(ggiraph)
library(tidyverse)
library(patchwork)
mtcars_db <- rownames_to_column(mtcars, var = "carname")
# First plot: Scatter plot
fig_pt <- ggplot(
data = mtcars_db,
mapping = aes(
x = disp, y = qsec,
tooltip = carname, data_id = carname
)
) +
geom_point_interactive(
size = 3, hover_nearest = TRUE
) +
labs(
title = "Displacement vs Quarter Mile",
x = "Displacement", y = "Quarter Mile"
) +
theme_bw()
# Second plot: Bar plot
fig_bar <- ggplot(
data = mtcars_db,
mapping = aes(
x = reorder(carname, mpg), y = mpg,
tooltip = paste("Car:", carname, "<br>MPG:", mpg),
data_id = carname
)
) +
geom_col_interactive(fill = "skyblue") +
coord_flip() +
labs(
title = "Miles per Gallon by Car",
x = "Car", y = "Miles per Gallon"
) +
theme_bw()
# Combine the plots using patchwork
combined_plot <- fig_pt + fig_bar + plot_layout(ncol = 2)
# Combine the plots using cowplot
# combined_plot <- cowplot::plot_grid(fig_pt, fig_bar, ncol=2)
# Create a single interactive plot with both subplots
interactive_plot <- girafe(ggobj = combined_plot)
# Set options for the interactive plot
girafe_options(
interactive_plot,
opts_hover(css = "fill:cyan;stroke:black;cursor:pointer;"),
opts_selection(type = "single", css = "fill:red;stroke:black;")
)
How a shiny App code might look of the above…
install.packages('rsconnect')
install.packages('rsconnect')rsconnect::setAccountInfo(name="<ACCOUNT>", token="<TOKEN>", secret="<SECRET>")https://shiny.posit.co/r/layouts/
For useful resources: https://shiny.posit.co/r/articles/ For useful examples: https://shiny.posit.co/r/articles/
see https://mastering-shiny.org/